package com.timous.web;


import com.timous.Entity.Tag;
import com.timous.Entity.Type;
import com.timous.service.BlogService;
import com.timous.service.TagService;
import com.timous.vo.BlogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TagShowController {

    @Autowired
    private TagService tagService;

    @Autowired
    private BlogService blogService;

    //id是当前活跃的一个
    @GetMapping("/tags/{id}")
    public String typers(@PageableDefault(size = 5, sort = {"id"}, direction = Sort.Direction.DESC)
                                     @PathVariable Long id, Pageable pageable, Model model){
        //查询所有的分类  数据小的时候想当与拿到全表
        List<Tag> tags = tagService.listTagTop(1000);

        if(id == -1){
            id = tags.get(0).getId();

        }

        model.addAttribute("tags" , tags);
        model.addAttribute("page" , blogService.listBlog(id , pageable));
        model.addAttribute("activeTagid" , id);
        return "blogtags";
    }




}
